<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>


<style type="text/css">
<!--
.cost_table {
	width: 90%;
	margin: 0 auto;
	padding: 5px;
	border-collapse: collapse;
	border-spacing: 0;
	border: 1px solid #999;
}

.cost_table th {
	
}

.cost_table td,.cost_table th {
	border: 1px solid #999;
	padding: 2px 3px;
}

.iscalculate {
	border: none !important;
	box-shadow: none !important;
}

.iscalculate,.isnotcalculate {
	
}
-->
</style>



<link rel="stylesheet" href="css/external/codemirror.css" />
<script src="js/libs/code/codemirror.js"></script>
<script src="js/libs/code/formatting.js"></script>

<br>
<table id="cost_table" class="cost_table">${costTemplate }
</table>
<br>


<textarea id="code" name="code" style="width:95%;margin: 10 auto"> </textarea>

<script type="text/javascript">
	var SUM = 2000000;
	function cc() {
		var e_js = "";
		//从上到下，从左到右
		//找到所有手工填写的
		$(".isnotcalculate").each(function(index, item) {
			var $item = $(item);
			var d_code = $item.data("code");
			var i_v = $item.val();
			if (!i_v || i_v == "") {
				i_v = 0;
			}
			e_js += "var " + d_code + "=" + i_v + ";";
		});

		$(".iscalculate").each(function(index, item) {
			var $item = $(item);
			var d_code = $item.data("code");
			var d_calculate = $item.data("calculate").replace(new RegExp("%", "gm"), "/100");

			e_js += "var " + d_code + "=" + d_calculate + ";";

		});

		//组合所有的js
		$(".iscalculate").each(function(index, item) {
			var $item = $(item);
			var d_code = $item.data("code");

			e_js += "$('#cost_" + d_code + "').val(" + d_code + ");";

		});

		$("#code").val(e_js);

		eval(e_js);
	}

	cc();

	$(".isnotcalculate").change(function() {
		cc();
	});

	var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
		lineNumbers : true,
		tabMode : "indent"
	});

	var totalLines = editor.lineCount();
	var totalChars = editor.getTextArea().value.length;
	editor.autoFormatRange({
		line : 0,
		ch : 0
	}, {
		line : totalLines,
		ch : totalChars
	});
</script>
